﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LitJson;
using System.IO;
using System.Text;
public class NewItemManager
{
    private static NewItemManager instance;
    public static NewItemManager Instance
    {
        get
        {
            if (instance == null) instance = new NewItemManager();
            return instance;
        }
    }

    public List<BackpackItem> BackPackItemList;
    private JsonData ItemConfig;

    public void LoadItemConfigData()
    {
        if (this.BackPackItemList == null)
        {
            this.BackPackItemList = new List<BackpackItem>();
        }
        this.ItemConfig = JsonMapper.ToObject(File.ReadAllText(Application.dataPath + "/Config/BackPackItems.json", Encoding.GetEncoding("GB2312")));
        this.DecodeJson();
    }

    private void DecodeJson()
    {
        for (int i= 0;i< this.ItemConfig.Count; i++)
        {
            int itemID = (int)this.ItemConfig[i]["ItemID"];
            string itemName = this.ItemConfig[i]["ItemName"].ToString();
            string itemDesc = this.ItemConfig[i]["ItemDesc"].ToString();
            int itemType = (int)this.ItemConfig[i]["ItemType"];
            string itemIcon = this.ItemConfig[i]["ItemIcon"].ToString();
            string itemBgIcon = this.ItemConfig[i]["ItemBgIcon"].ToString();
            int itemCount = (int)this.ItemConfig[i]["ItemCount"];
            int itemQuality = (int)this.ItemConfig[i]["ItemQuality"];
            int itemOpreation = (int)this.ItemConfig[i]["ItemOpreation"];

            //Debug.LogError(itemID  + " " + itemName + " " + itemDesc + " " + itemType + " " + itemIcon + " "
            //    + itemBgIcon + " " + itemCount + " " + itemQuality + " " + itemOpreation );
            BackpackItem item = new BackpackItem(itemID, itemName, itemDesc,
                itemType, itemIcon, itemBgIcon, itemCount, itemQuality, itemOpreation);
            this.BackPackItemList.Add(item);
        }
    }
    
}
